<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Send_sms extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('sms/sms_model','scm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('sms/themescript/moment.js')),
			script_tag(site_url('sms/themescript/app/sms_send.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'sms';
		$this->header['pagetitle'] = 'Send SMS';
		$this->view('sms/sms_send_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->scm->get_all($params);
		print(json_encode($result));
	}

	function send()
	{
		$this->load->library('curl'); 
		$this->load->helper('xml');

		$post 		= $this->input->post();
		$userkey	= '8adoni';
		$passkey 	= 'tessms';
		$nohp 		= $post['sms_no'];
		$text 		= $post['sms_desc'];

		$url1  = 'https://reguler.zenziva.net/apps/smsapi.php?userkey='.$userkey.'&passkey='.$passkey.'&nohp='.$nohp.'&pesan='.$text;
		$url2  = str_replace ( ' ', '%20', $url1);
		
		/* CURL */
		$curl = curl_init($url2);
		curl_setopt($curl, CURLOPT_FAILONERROR, true);
		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);  
		$result = curl_exec($curl);
		$res = $this->between('<text>', '</text>', $result);
		
		if($res == 'Success') $true = 'TRUE';
		else $true = 'FALSE';
		
		print(json_encode(array(
			'success' => $true
		)));
	}

	function between($var1, $var2, $inthat)
    {
        return $this->before($var2, $this->after($var1, $inthat));
    }

    function before($var3, $inthat)
    {
        return substr($inthat, 0, strpos($inthat, $var3));
    }

    function after($var4, $inthat)
    {
        if (!is_bool(strpos($inthat, $var4)))
        return substr($inthat, strpos($inthat,$var4)+strlen($var4));
    }

}

/* End of file sms_contact.php */
/* Location: .//D/OemahCode/hann/module_admin/sms/controllers/sms_contact.php */